<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>添加单选选项</title>
  <script src="/Application/Admin/View/Public/node_modules/jquery/dist/jquery.min.js"></script>

  <!-- select2库，用于多选下拉 -->
  <script src="/Application/Admin/View/Public/node_modules/select2/dist/js/select2.full.min.js"></script>
  <script src="/Application/Admin/View/Public/node_modules/select2/dist/js/i18n/zh-CN.js"></script>

  <link rel="stylesheet" href="/Application/Admin/View/Public/style/base.css">
  <!-- select2库，用于多选下拉 -->
  <link rel="stylesheet" href="/Application/Admin/View/Public/node_modules/select2/dist/css/select2.min.css" type="text/css" />
  <style>
    body{min-width: unset;min-height: unset;padding-left: 1rem;padding-bottom: 1rem;}
    input,button{display: block;}
    input{width: 40vw;line-height: 2rem;margin-bottom: 1rem;border: 1px solid #aaa;border-radius: 4px;}
  </style>
</head>
<body>
  <h1>填写多选选型</h1>
  <div class="input_wrap">
    <form autocomplete="off" action="">
      <input type="text" name = 0 placeholder="点击输入新选项名称" id='now'>
      <button onclick="submitThis(this, event)">提交</button>
    </form>
  </div>

  <script>
    let i = 1
    let thisFlame = parent.layer.getFrameIndex(window.name); //获取窗口索引

    // parent.layer.iframeAuto(thisFlame);

    // parent.$('#parentIframe').text('我被改变了');

    $(document).ready(function(){
      $('#now').one('focus', addNew)
    })
    function GetQueryString(name)
    {
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if(r!=null)return  unescape(r[2]); return null;
    }
    function addNew() {
      let templ = `<input type="text" name=${i++} placeholder="点击输入新选项名称" id='now'>`.trim()
      let _this = $('#now')
      _this.after(templ)
      _this.attr('id','had')
      $('#now').one('focus', addNew)
      // parent.layer.iframeAuto(thisFlame)
    }
    function submitThis(_this, evt) {
      evt.preventDefault()
      let array = $(_this).closest('form').serializeArray().filter(ele => {
        if (ele.value.replace(/[　\s]+/g,"").length > 0)
        return ele
      })
      if( array.length > 0) {
        let Arrayname = 'single'
        parent[Arrayname] = array
        parent.layer.close(thisFlame)
        let templName = GetQueryString('templName')
        parent.inori_func.addNewMultiplelLine(Arrayname, templName)
      } else {
        parent.layer.msg('请填写有效信息', {shade: 0.3})
      }
    }
  </script>
</body>
</html>